package com.netty.cn.model.socket.server.core;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
 
import java.util.UUID;
 
/**
 * 
 * @author wangzonghui
 * @date 2023-02-07 09:49:53
 * @Description 服务处理器
 */
public class MyServerHandler extends SimpleChannelInboundHandler<String> {
 
 
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        System.out.println(ctx.channel().remoteAddress() + "," + msg);
        ctx.channel().writeAndFlush("from service:" + UUID.randomUUID()+" 服务端响应：消息已接收");
    }
 
 
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.getCause();
        ctx.channel().close();
    }
}